using ASP;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Tuan_Default : Shop, IRequiresSessionState
{
	public string tag = "";
	public int flag = 0;
	public int PageSizeNum = 0;
	private string StrType = "";
	private string WhereStr = "";
	private string StrOrderby = " order by ProductID desc ";
	private int Pageindex = 1;
	private int ClassificationID = 0;
	private int PriceID = 0;
	private int SortingID = 0;
	private int ProductType = 0;
	public string ClassName1 = "";
	public string ClassName2 = "";
	public string ClassName3 = "";
	public string ClassName4 = "";
	public string ClassName5 = "";
	public string ParentID1 = "0";
	public string ParentID2 = "0";
	public string ParentID3 = "0";
	public string ParentID4 = "0";
	public string ParentID5 = "0";
	protected UserControls_cmpy_Top Top1;
	protected TextBox KeyBox;
	protected Button SearchButton;
	protected DataList DataList1;
	protected Label LbPage;
	protected UserControls_CMYP_Foot Foot1;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Init(object sender, EventArgs e)
	{
		try
		{
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ShopClass();
		if (!base.IsPostBack)
		{
			base.ShowCityArea();
			if (base.Request.QueryString["Type"] != null && base.Request.QueryString["Type"].ToString() != "")
			{
				this.StrType = base.Request.QueryString["Type"].ToString();
			}
			this.ProductDataBind(this.WhereStr, this.StrType, 0);
		}
	}
	public void WhereAddress()
	{
		SiteConfigBll siteConfigBll = new SiteConfigBll();
		if (siteConfigBll.GetSiteString("SiteConfigInfo/CityArea") != "0")
		{
			if (base.Request.Cookies["Howave_City"] != null)
			{
				string text = HttpUtility.UrlDecode(base.Request.Cookies["Howave_City"].Values["_Name"]).ToString();
				if (text != "全国")
				{
					this.WhereStr = " and ProductPlace like '%" + text + "%'";
				}
			}
		}
	}
	public void ProductDataBind(string CityAddress, string type, int JustID)
	{
		this.WhereAddress();
		CurrPageLinks currPageLinks = new CurrPageLinks();
		int pCount = 0;
		this.SearchMethod(type);
		if (JustID == 1)
		{
			this.Pageindex = 1;
		}
		int num = (this.Pageindex - 1) * 12;
		SqlParameter[] array = new SqlParameter[]
		{
			this.conn.CreateSQlParameter("@StrWhere", SqlDbType.VarChar, this.WhereStr, ParameterDirection.Input),
			this.conn.CreateSQlParameter("@StrOrderby", SqlDbType.VarChar, this.StrOrderby, ParameterDirection.Input),
			this.conn.CreateSQlParameter("@PageSize", SqlDbType.VarChar, num, ParameterDirection.Input),
			this.conn.CreateSQlParameter("@TotalCount", SqlDbType.Int, 0, ParameterDirection.Output)
		};
		DataTable dataTable = this.conn.GetDataTable("PR_GetMarketAndSecondkillsAndTuan", array);
		this.PageSizeNum = dataTable.Rows.Count;
		this.DataList1.DataSource = dataTable;
		this.DataList1.DataBind();
		if (array[3].Value != null && array[3].Value.ToString() != "")
		{
			pCount = int.Parse(array[3].Value.ToString());
		}
		dataTable.Dispose();
		this.LbPage.Text = currPageLinks.CurrPageLink(this.Pageindex, 12, pCount, "个商品", string.Concat(new object[]
		{
			"default.aspx?Type=",
			type,
			"&Classification=",
			this.ClassificationID,
			"&Price=",
			this.PriceID,
			"&Sorting=",
			this.SortingID,
			"&JustPage=0&pageindex"
		}));
	}
	public string ShowProductType(string ProductID)
	{
		object[] dataNum = this.GetDataNum(int.Parse(ProductID));
		return dataNum[3].ToString();
	}
	public string ShowRebate(string ProductID)
	{
		object[] dataNum = this.GetDataNum(int.Parse(ProductID));
		return dataNum[1].ToString();
	}
	public string ShowYuanPrice(string ProductID)
	{
		string result = "";
		object[] dataNum = this.GetDataNum(int.Parse(ProductID));
		switch (int.Parse(dataNum[6].ToString()))
		{
		case 1:
			if (decimal.Parse(dataNum[5].ToString()) > decimal.Parse(dataNum[4].ToString()))
			{
				result = dataNum[5].ToString();
			}
			else
			{
				result = dataNum[4].ToString();
			}
			break;
		case 3:
			result = dataNum[4].ToString();
			break;
		case 4:
			if (decimal.Parse(dataNum[5].ToString()) > decimal.Parse(dataNum[4].ToString()))
			{
				result = dataNum[5].ToString();
			}
			else
			{
				result = dataNum[4].ToString();
			}
			break;
		}
		return result;
	}
	public string ShowNowPrice(string ProductID)
	{
		object[] dataNum = this.GetDataNum(int.Parse(ProductID));
		string result;
		if (int.Parse(dataNum[6].ToString()) == 3)
		{
			result = dataNum[0].ToString();
		}
		else
		{
			result = dataNum[4].ToString();
		}
		return result;
	}
	public object[] GetDataNum(int ProductID)
	{
		decimal num = 0m;
		decimal num2 = 0m;
		decimal num3 = 10m;
		decimal num4 = 0m;
		object[] array = new object[]
		{
			0,
			0,
			0,
			0,
			0,
			0,
			0
		};
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_Product where ProductID=" + ProductID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			int num5 = int.Parse(dataTable.Rows[0]["TeamNum"].ToString());
			if (num5 > 0)
			{
				num = decimal.Parse(dataTable.Rows[0]["TeamPrice" + num5].ToString());
			}
			decimal num6 = decimal.Parse(dataTable.Rows[0]["StandPrice"].ToString());
			if (!string.IsNullOrEmpty(dataTable.Rows[0]["MemberPrice"].ToString()))
			{
				num2 = decimal.Parse(dataTable.Rows[0]["MemberPrice"].ToString());
			}
			array[0] = num;
			array[6] = dataTable.Rows[0]["ProductType"].ToString();
			switch (int.Parse(dataTable.Rows[0]["ProductType"].ToString()))
			{
			case 1:
				array[3] = "一口价";
				if (num2 > 0m && num2 > num6)
				{
					num3 = Math.Round(num6 / num2 * 10m, 2);
					num4 = num2 - num6;
				}
				else
				{
					num3 = decimal.Parse("10.0");
					num4 = 0m;
				}
				break;
			case 3:
				array[3] = "团购价";
				num3 = Math.Round(num / num6 * 10m, 2);
				num4 = num6 - num;
				break;
			case 4:
				array[3] = "秒杀价";
				if (num2 > 0m && num2 > num6)
				{
					num3 = Math.Round(num6 / num2 * 10m, 2);
					num4 = num2 - num6;
				}
				else
				{
					num3 = decimal.Parse("10.0");
					num4 = 0m;
				}
				break;
			}
			array[1] = num3;
			array[2] = num4;
			array[4] = num6;
			array[5] = num2;
		}
		dataTable.Dispose();
		return array;
	}
	protected void SearchButton_Click(object sender, EventArgs e)
	{
		if (this.KeyBox.Text != "")
		{
			this.WhereStr = this.WhereStr + " and ProductName like '%" + this.KeyBox.Text + "%' ";
		}
		if (base.Request.QueryString["Type"] != null && base.Request.QueryString["Type"].ToString() != "")
		{
			this.StrType = base.Request.QueryString["Type"].ToString();
		}
		this.ProductDataBind(this.WhereStr, this.StrType, 1);
	}
	public void ShopClass()
	{
		DataTable dataTable = this.conn.GetDataTable("select top 5 * from HLShop_Class order by ParentID asc");
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			this.ClassName1 = dataTable.Rows[0]["ClassName"].ToString().Substring(0, 2);
			this.ParentID1 = dataTable.Rows[0]["ClassID"].ToString();
			this.ClassName2 = dataTable.Rows[1]["ClassName"].ToString().Substring(0, 2);
			this.ParentID2 = dataTable.Rows[1]["ClassID"].ToString();
			this.ClassName3 = dataTable.Rows[2]["ClassName"].ToString().Substring(0, 2);
			this.ParentID3 = dataTable.Rows[2]["ClassID"].ToString();
			this.ClassName4 = dataTable.Rows[3]["ClassName"].ToString().Substring(0, 2);
			this.ParentID4 = dataTable.Rows[3]["ClassID"].ToString();
			this.ClassName5 = dataTable.Rows[4]["ClassName"].ToString().Substring(0, 2);
			this.ParentID5 = dataTable.Rows[4]["ClassID"].ToString();
		}
		dataTable.Dispose();
	}
	public void SearchMethod(string type)
	{
		if (type != null)
		{
			if (!(type == "market"))
			{
				if (!(type == "teamBuy"))
				{
					if (!(type == "auctionMall"))
					{
						if (type == "")
						{
							this.WhereStr += " and (ProductType=1 or ProductType=4 or ProductType=3) ";
							this.ProductType = 0;
						}
					}
					else
					{
						this.flag = 4;
						this.WhereStr += " and ProductType=4 ";
						this.ProductType = 4;
					}
				}
				else
				{
					this.flag = 3;
					this.WhereStr += " and ProductType=3 ";
					this.ProductType = 3;
				}
			}
			else
			{
				this.flag = 1;
				this.WhereStr += " and ProductType=1 ";
				this.ProductType = 1;
			}
		}
		if (base.Request.QueryString["pageindex"] != null)
		{
			if (base.Request.QueryString["pageindex"].ToString() != "")
			{
				if (Tuan_Default.IsNumberic(base.Request.QueryString["pageindex"].ToString()) && base.Request.QueryString["JustPage"] != null)
				{
					this.Pageindex = int.Parse(base.Request.QueryString["pageindex"].ToString());
				}
				else
				{
					this.Pageindex = 1;
				}
			}
		}
		if (base.Request.QueryString["Classification"] != null)
		{
			if (base.Request.QueryString["Classification"].ToString() != "")
			{
				if (Tuan_Default.IsNumberic(base.Request.QueryString["Classification"].ToString()))
				{
					this.ClassificationID = int.Parse(base.Request.QueryString["Classification"].ToString());
					if (this.ClassificationID != 0 && this.ClassificationID != -1)
					{
						object whereStr = this.WhereStr;
						this.WhereStr = string.Concat(new object[]
						{
							whereStr,
							" and ClassID in (select ClassID from HLShop_Class where ParentID=",
							this.ClassificationID,
							") "
						});
					}
					else
					{
						if (this.ClassificationID == -1)
						{
							string whereStr2 = this.WhereStr;
							this.WhereStr = string.Concat(new string[]
							{
								whereStr2,
								" and ClassID not in (select ClassID from HLShop_Class where ParentID in (",
								this.ParentID1,
								",",
								this.ParentID2,
								",",
								this.ParentID3,
								",",
								this.ParentID4,
								" ,",
								this.ParentID5,
								"))"
							});
						}
					}
				}
			}
		}
		if (base.Request.QueryString["Price"] != null)
		{
			if (base.Request.QueryString["Price"].ToString() != "")
			{
				if (Tuan_Default.IsNumberic(base.Request.QueryString["Price"].ToString()))
				{
					this.PriceID = int.Parse(base.Request.QueryString["Price"].ToString());
					switch (this.PriceID)
					{
					case 1:
						if (this.ProductType == 1 || this.ProductType == 4)
						{
							this.WhereStr += " and (StandPrice<=50 and StandPrice>0) ";
						}
						else
						{
							if (this.ProductType == 3)
							{
								this.WhereStr += " and ((TeamPrice1>0 and TeamPrice1<=50 and TeamNum=1) or(TeamPrice2>=0 and TeamPrice2<=50 and TeamNum=2) or (TeamPrice3>0 and TeamPrice3<=50 and TeamNum=3) or (TeamPrice4>0 and TeamPrice4<=50 and TeamNum=4) or (TeamPrice5>0 and TeamPrice5<=50 and TeamNum=5)) ";
							}
							else
							{
								if (this.ProductType == 0)
								{
									this.WhereStr += " and (((StandPrice<=50 and StandPrice>0) and (ProductType=1 or ProductType=4)) or ((TeamPrice1>0 and TeamPrice1<=50 and TeamNum=1) or(TeamPrice2>=0 and TeamPrice2<=50 and TeamNum=2) or (TeamPrice3>0 and TeamPrice3<=50 and TeamNum=3) or (TeamPrice4>0 and TeamPrice4<=50 and TeamNum=4) or (TeamPrice5>0 and TeamPrice5<=50 and TeamNum=5))) ";
								}
							}
						}
						break;
					case 2:
						if (this.ProductType == 1 || this.ProductType == 4)
						{
							this.WhereStr += " and (StandPrice<=100 and StandPrice>50) ";
						}
						else
						{
							if (this.ProductType == 3)
							{
								this.WhereStr += " and ((TeamPrice1>50 and TeamPrice1<=100 and TeamNum=1) or(TeamPrice2>=50 and TeamPrice2<=100 and TeamNum=2) or (TeamPrice3>50 and TeamPrice3<=100 and TeamNum=3) or (TeamPrice4>50 and TeamPrice4<=100 and TeamNum=4) or (TeamPrice5>50 and TeamPrice5<=100 and TeamNum=5)) ";
							}
							else
							{
								if (this.ProductType == 0)
								{
									this.WhereStr += " and (((StandPrice<=100 and StandPrice>50) and (ProductType=1 or ProductType=4)) or ((TeamPrice1>50 and TeamPrice1<=100 and TeamNum=1) or (TeamPrice2>=50 and TeamPrice2<=100 and TeamNum=2) or (TeamPrice3>50 and TeamPrice3<=100 and TeamNum=3) or (TeamPrice4>50 and TeamPrice4<=100 and TeamNum=4) or (TeamPrice5>50 and TeamPrice5<=100 and TeamNum=5))) ";
								}
							}
						}
						break;
					case 3:
						if (this.ProductType == 1 || this.ProductType == 4)
						{
							this.WhereStr += " and (StandPrice<=200 and StandPrice>100) ";
						}
						else
						{
							if (this.ProductType == 3)
							{
								this.WhereStr += " and ((TeamPrice1>100 and TeamPrice1<=200 and TeamNum=1) or(TeamPrice2>=100 and TeamPrice2<=200 and TeamNum=2) or (TeamPrice3>100 and TeamPrice3<=200 and TeamNum=3) or (TeamPrice4>100 and TeamPrice4<=200 and TeamNum=4) or (TeamPrice5>100 and TeamPrice5<=200 and TeamNum=5)) ";
							}
							else
							{
								if (this.ProductType == 0)
								{
									this.WhereStr += " and (((StandPrice<=200 and StandPrice>100) and (ProductType=1 or ProductType=4)) or ((TeamPrice1>100 and TeamPrice1<=200 and TeamNum=1) or(TeamPrice2>=100 and TeamPrice2<=200 and TeamNum=2) or (TeamPrice3>100 and TeamPrice3<=200 and TeamNum=3) or (TeamPrice4>100 and TeamPrice4<=200 and TeamNum=4) or (TeamPrice5>100 and TeamPrice5<=200 and TeamNum=5)))";
								}
							}
						}
						break;
					case 4:
						if (this.ProductType == 1 || this.ProductType == 4)
						{
							this.WhereStr += " and (StandPrice<=300 and StandPrice>200) ";
						}
						else
						{
							if (this.ProductType == 3)
							{
								this.WhereStr += " and ((TeamPrice1>200 and TeamPrice1<=300 and TeamNum=1) or(TeamPrice2>=200 and TeamPrice2<=300 and TeamNum=2) or (TeamPrice3>200 and TeamPrice3<=300 and TeamNum=3) or (TeamPrice4>200 and TeamPrice4<=300 and TeamNum=4) or (TeamPrice5>200 and TeamPrice5<=300 and TeamNum=5)) ";
							}
							else
							{
								if (this.ProductType == 0)
								{
									this.WhereStr += " and (((StandPrice<=300 and StandPrice>200) and (ProductType=1 or ProductType=4)) or ((TeamPrice1>200 and TeamPrice1<=300 and TeamNum=1) or(TeamPrice2>=200 and TeamPrice2<=300 and TeamNum=2) or (TeamPrice3>200 and TeamPrice3<=300 and TeamNum=3) or (TeamPrice4>200 and TeamPrice4<=300 and TeamNum=4) or (TeamPrice5>200 and TeamPrice5<=300 and TeamNum=5))) ";
								}
							}
						}
						break;
					case 5:
						if (this.ProductType == 1 || this.ProductType == 4)
						{
							this.WhereStr += " and StandPrice>300 ";
						}
						else
						{
							if (this.ProductType == 3)
							{
								this.WhereStr += " and ((TeamNum=1 and TeamPrice1>300) or (TeamNum=2 and TeamPrice2>300) or (TeamNum=3 and TeamPrice3>300) or (TeamNum=4 and TeamPrice4>300) or (TeamNum=5 and TeamPrice5>300))  ";
							}
							else
							{
								if (this.ProductType == 0)
								{
									this.WhereStr += " and (((StandPrice>300 and ProductType=1) or (StandPrice>300 and ProductType=4)) or ((TeamNum=1 and TeamPrice1>300) or (TeamNum=2 and TeamPrice2>=300) or (TeamNum=3 and TeamPrice3>300) or (TeamNum=4 and TeamPrice4>300) or (TeamNum=5 and TeamPrice5>300))) ";
								}
							}
						}
						break;
					}
				}
			}
		}
		if (base.Request.QueryString["Sorting"] != null)
		{
			if (base.Request.QueryString["Sorting"].ToString() != "")
			{
				if (Tuan_Default.IsNumberic(base.Request.QueryString["Sorting"].ToString()))
				{
					this.SortingID = int.Parse(base.Request.QueryString["Sorting"].ToString());
					switch (this.SortingID)
					{
					case 1:
						this.StrOrderby = " order by ProductID desc ";
						break;
					case 2:
						this.StrOrderby = " order by CreateTime desc ";
						break;
					case 4:
						this.StrOrderby = " order by Hits desc ";
						break;
					}
				}
			}
		}
	}
	public static bool IsNumberic(string oText)
	{
		bool result;
		try
		{
			int num = Convert.ToInt32(oText);
			result = true;
		}
		catch
		{
			result = false;
		}
		return result;
	}
}
